import redis
from fastapi import FastAPI
from fastapi.templating import Jinja2Templates


class RedisConfig:

    host = 'localhost'
    port = 16379


def register_redis(app: FastAPI):
    r = redis.Redis(host=RedisConfig.host, port=RedisConfig.port, decode_responses=True, charset='UTF-8')

    print('redis client prepared!', r.ping())

    @app.on_event("startup")
    def startup_event():
        app.state.redis = r
